#!/bin/bash

count=$(cat $3 | grep '^[0-9]\{4\}' | wc -l | sed 's/[ 	]*//g')
echo "There are $count scored rows"

middle=$(expr $count / 2 + 1)

HTMED=$(cat $3 | grep '^[0-9]\{4\}' | sed -f sed5Col | sort -n | sed -n "${middle}p")
EXMED=$(cat $3 | grep '^[0-9]\{4\}' | sed 's/.*[ ]\{1\}\([0-9]*\)$/\1/' | sort -n | sed -n "${middle}p" )

echo "HT Median: $HTMED"
echo "EXAM Median: $EXMED"

echo "Student scores:"
cat $3 | grep "^IDNO"
cat $3 | grep "^$1"

columnNum=$(./getColumnNum HT $3)
HTScore=$(./getColumn $1 $columnNum $3)
HTCalc=$(expr $2 - $HTScore)

columnNum=$(./getColumnNum EXAM $3)
EXAMScore=$(./getColumn $1 $columnNum $3)
EXAMCalc=$(expr $2 - $EXAMScore)

echo "$2 - HT: $HTCalc"
echo "$2 - EXAM: $EXAMCalc"
